import { queryCompanyUsers } from '@/api/users.js';
import { validateNameCNLU, nameErrorTipCNLU, getNumReg } from '@/libs/reg';
import { kyTypeMixin, kySourceMixin } from '../mixin/research';
const formDataMixin = {
    mixins:[kyTypeMixin,kySourceMixin],
    data() {
        return {
            allDesignerList:[],
            sourceList:[],
            formData:{
                serial:{
                    value:'',
                    label:'项目编号',
                    component:'Input',
                    rule:{
                        required: true
                    }
                },
                name: {
                    value:'',
                    label:'项目名称',
                    component:'Input',
                    placeholder:nameErrorTipCNLU,
                    rule:{
                        required: true,
                        validator: validateNameCNLU
                    },
                    props:{
                        maxlength:64
                    }
                },
                typeCode: {
                    value:'',
                    label:'项目类别',
                    component:'Select',
                    options:() => {
                        return this.kyTypeArr.map(item => {
                            return {
                                ...item,
                                label:item.dictname,
                                value:item.dictid
                            }
                        })
                    },
                    rule:{
                        required: true
                    }
                },
                emphasis: {
                    value:1,
                    label:'重点项目',
                    component:'RadioGroup',
                    options:() => {
                        return [
                            {
                                label:'是',
                                value:1
                            },
                            {
                                label:'否',
                                value:0
                            }
                        ]
                    },
                    rule:{
                        required: true,
                        type:'number'
                    }
                },
                source:{
                    value:'',
                    label:'项目来源',
                    component:'Select',
                    options:() => {
                        return this.kySourceArr.map(item => {
                            return {
                                ...item,
                                label:item.dictname,
                                value:item.dictid
                            }
                        })
                    },
                    rule:{
                        required: true
                    }
                }, 
                forms:{
                    value:'',
                    component:'Input',
                    label:'合作形式'
                }, 
                expenditure:{
                    value:0,
                    component:'InputNumber',
                    label:'预算经费（万元）',
                    rule:{
                        type:'number',
                        min:0,
                        required: true
                    }
                }, 
                time:{
                    value:[],
                    component:'FormDatepicker',
                    label:'项目时间',
                    rule:{
                        required: true,
                        type:'array',
                        min:2,
                        max:2
                    }
                },
                accepter:{
                    value:'',
                    component:'Select',
                    label:'负责人员',
                    options:() => {
                        return this.rootDesignerList.map(item => {
                            return {
                                ...item,
                                label:item.nickname,
                                value:item.id
                            }
                        })
                    },
                },
                description: {
                    value:'',
                    component:'Input',
                    props:{
                        type:'textarea',
                        autosize:{minRows: 2,maxRows: 5},
                        maxlength:200
                    },
                    label:'描述'
                },
                iconPath:{
                    value:'',
                    component:'ItemUpload',
                    label:'封面图片'
                },
            }
        }
    },
    computed:{
        rootDesignerList() {
            //单位管理员
            return this.allDesignerList.filter((designer) => designer.role === 'leader');
        },
        designerList() {
            //单位设计师
            return this.allDesignerList.filter((designer) => designer.role === 'member');
        }
    },
    methods: {
        // 单位人员列表
        getCompanyUserList() {
            // let role = this.type === 'apply' ? 'leader' : 'member';
            let params = {
                pageIndex: 1,
                pageSize: 1000000,
                order: 'desc',
                sortBy: 'created',
                type: 'designer',
                // role: role //member / leader
            };
            queryCompanyUsers(params)
                .then(({ code, data, message }) => {
                    if (code === 1) {
                        this.allDesignerList = data.items;
                    } else {
                    }
                })
                .catch((err) => {});
        },
        getOptionsData(item) {
            return typeof item.options === 'function'
                ? item.options()
                : item.options
                ? item.options
                : [];
        }
    }
};
export { formDataMixin };
